package cn.edu.njust.alg.leetcode;

/**
 * 创建时间：2015年6月15日 上午11:47:37 项目名称：AlgorithmExercise
 * 
 * @author Zhou Xiumin
 * @version 1.0
 * @since JDK 1.7.0_21 文件名称：Leetcode_0_t.java 类说明：
 */
public class Leetcode_165_Compare_Version_Numbers {

	public static int compareVersion(String version1, String version2) {

		String[] s1 = version1.split("\\.");
		String[] s2 = version2.split("\\.");
		int len = Math.min(s1.length, s2.length);
		for (int i = 0; i < len; i++) {
			int k1 = Integer.parseInt(s1[i]);
			int k2 = Integer.parseInt(s2[i]);
			if (k1 > k2) {
				return 1;
			} else if (k1 < k2) {
				return -1;
			}
		}
		String[] maxs = null;
		int flag = 1;
		if (s1.length > s2.length) {
			maxs = s1;
		} else {
			maxs = s2;
			flag = -1;
		}
		for (int i = len; i < maxs.length; i++) {
			if (Integer.parseInt(maxs[i]) != 0) {
				return flag;
			}
		}
		return 0;
	}

	public static void main(String[] args) {
		String version1 = "1.0";
		String version2 = "1";

		System.out.println(compareVersion(version1, version2));
	}

}
